package com.kitty.mybatis.mybatisv1.binding;

import com.kitty.mybatis.mybatisv1.session.KittyConfiguration;
import com.kitty.mybatis.mybatisv1.session.KittySqlSession;

import java.lang.reflect.Method;

/**
 * @Description
 * @Author SHEN
 * @Date 2020/10/22
 */
public class KittyMapperMethod {

    private final KittySqlCommand command;

    private final KittyMethodSignature methodSignature;

    public KittyMapperMethod(Class<?> clazz, Method method, KittyConfiguration configuration) {
        this.command = new KittySqlCommand(configuration,clazz,method);
        this.methodSignature = new KittyMethodSignature(configuration,method);
    }

    public Object execute(KittySqlSession sqlSession,Object[] args){
        Object result = null;
        Object param = methodSignature.convertArgsToSqlCommandParam(args);
        result = sqlSession.selectOne(command.getName(), param);
        return result;
    }

}
